@echo off
REM Git Hooks Controller - 复制到本地仓库脚本
echo Git Hooks Controller - Copy to Local Repository
echo ================================================

set TARGET_REPO=F:\sdl\git hooks\git-hooks-controller

echo Target repository: %TARGET_REPO%
echo.

if not exist "%TARGET_REPO%" (
    echo ERROR: Target repository does not exist!
    echo Please check the path: %TARGET_REPO%
    pause
    exit /b 1
)

if not exist "%TARGET_REPO%\.git" (
    echo ERROR: Target directory is not a Git repository!
    pause
    exit /b 1
)

echo Copying files to local repository...
echo.

REM 复制核心目录
echo [1/4] Copying core directories...
robocopy "core" "%TARGET_REPO%\core" /E /R:1 /W:1 /NP /XD __pycache__ >nul
robocopy "plugins" "%TARGET_REPO%\plugins" /E /R:1 /W:1 /NP /XD __pycache__ >nul
robocopy "tools" "%TARGET_REPO%\tools" /E /R:1 /W:1 /NP /XD __pycache__ >nul
robocopy "config" "%TARGET_REPO%\config" /E /R:1 /W:1 /NP >nul
robocopy "examples" "%TARGET_REPO%\examples" /E /R:1 /W:1 /NP >nul
robocopy "docs" "%TARGET_REPO%\docs" /E /R:1 /W:1 /NP >nul

REM 复制项目文件
echo [2/4] Copying project files...
copy /Y "pyproject.toml" "%TARGET_REPO%\" >nul 2>&1
copy /Y "setup.py" "%TARGET_REPO%\" >nul 2>&1
copy /Y "requirements.txt" "%TARGET_REPO%\" >nul 2>&1
copy /Y ".gitignore" "%TARGET_REPO%\" >nul 2>&1
copy /Y "README.md" "%TARGET_REPO%\" >nul 2>&1

REM 复制文档
echo [3/4] Copying documentation...
copy /Y "ENHANCED_COMMIT_VALIDATION.md" "%TARGET_REPO%\" >nul 2>&1
copy /Y "HOW_TO_USE.md" "%TARGET_REPO%\" >nul 2>&1
copy /Y "USER_GUIDE.md" "%TARGET_REPO%\" >nul 2>&1
copy /Y "SETUP_GUIDE.md" "%TARGET_REPO%\" >nul 2>&1
copy /Y "TROUBLESHOOTING.md" "%TARGET_REPO%\" >nul 2>&1
copy /Y "PROJECT_SUMMARY.md" "%TARGET_REPO%\" >nul 2>&1
copy /Y "VERIFICATION_REPORT.md" "%TARGET_REPO%\" >nul 2>&1

REM 复制脚本
echo [4/4] Copying scripts...
copy /Y "demo_simple.py" "%TARGET_REPO%\" >nul 2>&1
copy /Y "demo.py" "%TARGET_REPO%\" >nul 2>&1
copy /Y "simple_test.py" "%TARGET_REPO%\" >nul 2>&1
copy /Y "test_system.py" "%TARGET_REPO%\" >nul 2>&1
copy /Y "test_enhanced_commit_validation.py" "%TARGET_REPO%\" >nul 2>&1
copy /Y "quick-start.bat" "%TARGET_REPO%\" >nul 2>&1
copy /Y "quick-start.sh" "%TARGET_REPO%\" >nul 2>&1
copy /Y "check_system.bat" "%TARGET_REPO%\" >nul 2>&1
copy /Y "check_system.sh" "%TARGET_REPO%\" >nul 2>&1

echo.
echo Copy completed successfully!
echo.

REM 切换到目标仓库
cd /d "%TARGET_REPO%"

echo Current directory: %CD%
echo.
echo Checking Git status...
git status

echo.
echo Files have been copied to your local repository.
echo You can now commit and push:
echo.
echo   git add .
echo   git commit -m "feat: finalize enhanced commit validation system
echo.
echo   Issue: Project cleanup and finalization
echo   - Completed enhanced commit message validation
echo   - Added Issue reference detection and Signed-off-by validation
echo   - Cleaned up project structure
echo   - Updated all documentation
echo.
echo   Signed-off-by: Your Name <your.email@huawei.com>"
echo.
echo   git push
echo.

set /p do_git="Do you want to run git commands now? (y/N): "
if /i not "%do_git%"=="y" (
    echo You can run the git commands manually when ready.
    pause
    exit /b 0
)

echo.
echo Running git add...
git add .

echo.
echo Running git commit...
git commit -m "feat: finalize enhanced commit validation system

Issue: Project cleanup and finalization
- Completed enhanced commit message validation with Issue reference detection
- Added Signed-off-by validation with email domain restrictions
- Cleaned up project structure and removed temporary files
- Updated all documentation and test suites
- Finalized core functionality for production use

Signed-off-by: Git Hooks Controller <admin@huawei.com>"

if %errorlevel% neq 0 (
    echo.
    echo Commit failed! You can try manually:
    echo git commit --no-verify -m "feat: finalize enhanced validation system"
    pause
    exit /b 1
)

echo.
echo Running git push...
git push

if %errorlevel% neq 0 (
    echo.
    echo Push failed! You may need to set up remote repository:
    echo git remote add origin https://gitcode.com/username/repo.git
    echo git push -u origin main
    pause
    exit /b 1
)

echo.
echo SUCCESS: All files copied and pushed to GitCode!
echo.
pause
